require.config({
	shim:{
        'calendar':{exports:'calendar'}
    },
    paths : {
        //"vue":"lib/vue",
        "jquery":"lib/jquery",
        "cmd":"cmd",
        "calendar":"lib/datepicker/WdatePicker",
    }
});

require(['jquery','cmd','calendar'],function($){

//get top menu
var token = detectToken();


//默认加载操作日志列表
$.vloading.show();
$.ajax({ 
    type:"post", 
    url:urls.checkHandellog, 
    data: {token:token,pageNow:1,pageSize:20}, 
    dataType: 'json', 
    async : true,
    success:function(result){
        $.vloading.remove();
        var  checkHandellogHtml = '';
        if(result.code=="1"){
          for(var i=0;i<result.data.records.length;i++){
              if(result.data.records[i].isSuccess==1){//0失败 1成功
                  checkHandellogHtml +='<div class="tableTReach clearfix">\n\
                        <div class="tablecommoncel-1 tableTBdpoint fl"><i data-ids="'+result.data.records[i].id+'" class="xwl i-checkno"></i></div>\n\
                        <div class="tablecommoncel-2 tableTBdZH fl oellipsis">'+result.data.records[i].accountName+'</div>\n\
                        <div class="tablecommoncel-3 tableTBdDTU fl">'+result.data.records[i].dtu_id+'</div>\n\
                        <div class="tablecommoncel-4 tableTBdMK fl oellipsis">'+result.data.records[i].module+'</div>\n\
                        <div class="tablecommoncel-5 tableTBdFF fl oellipsis">'+result.data.records[i].method+'</div>\n\
                        <div class="tablecommoncel-6 tableTBdIP fl oellipsis">'+result.data.records[i].userIP+'</div>\n\
                        <div class="tablecommoncel-7 tableTBdMS fl">'+result.data.records[i].description+'</div>\n\
                        <div class="tablecommoncel-8 tableTBdJG fl">成功</div>\n\
                        <div class="tablecommoncel-9 tableTBdSJ fl">'+result.data.records[i].operTime+'</div>\n\
                      </div>';
              }else{
                  checkHandellogHtml +='<div class="tableTReach clearfix">\n\
                        <div class="tablecommoncel-1 tableTBdpoint fl"><i data-ids="'+result.data.records[i].id+'" class="xwl i-checkno"></i></div>\n\
                        <div class="tablecommoncel-2 tableTBdZH fl oellipsis">'+result.data.records[i].accountName+'</div>\n\
                        <div class="tablecommoncel-3 tableTBdDTU fl">'+result.data.records[i].dtu_id+'</div>\n\
                        <div class="tablecommoncel-4 tableTBdMK fl oellipsis">'+result.data.records[i].module+'</div>\n\
                        <div class="tablecommoncel-5 tableTBdFF fl oellipsis">'+result.data.records[i].method+'</div>\n\
                        <div class="tablecommoncel-6 tableTBdIP fl oellipsis">'+result.data.records[i].userIP+'</div>\n\
                        <div class="tablecommoncel-7 tableTBdMS fl">'+result.data.records[i].description+'</div>\n\
                        <div class="tablecommoncel-8 tableTBdJG fl">失败</div>\n\
                        <div class="tablecommoncel-9 tableTBdSJ fl">'+result.data.records[i].operTime+'</div>\n\
                      </div>';
              }

          }
          $(".checkHandellogHtml").html(checkHandellogHtml);
          //总条数
          $(".allRecord").html(result.data.rowCount);
          //总页数
          $(".allpagesNums").html(result.data.pageCount);
            pageNav.go(1,result.data.pageCount);
            pageNav.fn = function(p,pn){
              if($("#timerfilterBtn").attr("data-coding")==0){//没有点击查询按钮
                getHandelLog(p);
                return;              
              }
            };
        }else{
          $.flytip("服务器繁忙，请稍后再试");
        }
    } 
});
//默认加载操作日志列表(封装)
var getHandelLog = function(curNums){
  var dtu_id = $("#eventDtuId").val();
  var accountName = $("#eventkehuName").val();
  var module = $("#logmodules").val();
  var methods = $("#logmoduleMethods").val();
  var isSuccess = $("#logmoduleResult").val();
  var createStartDate = $("#startDate").val();
  var createStartEnd = $("#endDate").val();
  var pageNow = curNums;
  var pageSize = 20;
  $.vloading.show();
    $.ajax({ 
        type:"post", 
        url:urls.checkHandellog, 
        data: {token:token,dtu_id:dtu_id,accountName:accountName,module:module,methods:methods,isSuccess:isSuccess,createStartDate:createStartDate,createStartEnd:createStartEnd,pageNow:curNums,pageSize:pageSize}, 
        dataType: 'json', 
        async : true,
        success:function(result){
          $.vloading.remove();
            var  checkHandellogHtml = '';
            if(result.data.records.length==0){
              $(".checkHandellogHtml").html('<p class="txtc" style="padding:19px 0;font-size:16px;border-right:1px solid #e9e9e9;border-bottom:1px solid #e9e9e9;">暂无数据</p>');
            }else{
              for(var i=0;i<result.data.records.length;i++){
                  if(result.data.records[i].isSuccess==1){//0失败 1成功
                      checkHandellogHtml +='<div class="tableTReach clearfix">\n\
                            <div class="tablecommoncel-1 tableTBdpoint fl"><i data-ids="'+result.data.records[i].id+'" class="xwl i-checkno"></i></div>\n\
                            <div class="tablecommoncel-2 tableTBdZH fl oellipsis">'+result.data.records[i].accountName+'</div>\n\
                            <div class="tablecommoncel-3 tableTBdDTU fl">'+result.data.records[i].dtu_id+'</div>\n\
                            <div class="tablecommoncel-4 tableTBdMK fl oellipsis">'+result.data.records[i].module+'</div>\n\
                            <div class="tablecommoncel-5 tableTBdFF fl oellipsis">'+result.data.records[i].method+'</div>\n\
                            <div class="tablecommoncel-6 tableTBdIP fl oellipsis">'+result.data.records[i].userIP+'</div>\n\
                            <div class="tablecommoncel-7 tableTBdMS fl">'+result.data.records[i].description+'</div>\n\
                            <div class="tablecommoncel-8 tableTBdJG fl">成功</div>\n\
                            <div class="tablecommoncel-9 tableTBdSJ fl">'+result.data.records[i].operTime+'</div>\n\
                          </div>';
                  }else{
                      checkHandellogHtml +='<div class="tableTReach clearfix">\n\
                            <div class="tablecommoncel-1 tableTBdpoint fl"><i data-ids="'+result.data.records[i].id+'" class="xwl i-checkno"></i></div>\n\
                            <div class="tablecommoncel-2 tableTBdZH fl oellipsis">'+result.data.records[i].accountName+'</div>\n\
                            <div class="tablecommoncel-3 tableTBdDTU fl">'+result.data.records[i].dtu_id+'</div>\n\
                            <div class="tablecommoncel-4 tableTBdMK fl oellipsis">'+result.data.records[i].module+'</div>\n\
                            <div class="tablecommoncel-5 tableTBdFF fl oellipsis">'+result.data.records[i].method+'</div>\n\
                            <div class="tablecommoncel-6 tableTBdIP fl oellipsis">'+result.data.records[i].userIP+'</div>\n\
                            <div class="tablecommoncel-7 tableTBdMS fl">'+result.data.records[i].description+'</div>\n\
                            <div class="tablecommoncel-8 tableTBdJG fl">失败</div>\n\
                            <div class="tablecommoncel-9 tableTBdSJ fl">'+result.data.records[i].operTime+'</div>\n\
                          </div>';
                  }

              }
              $(".checkHandellogHtml").html(checkHandellogHtml);              
            }

            //总条数
            $(".allRecord").html(result.data.rowCount);
            //总页数
            $(".allpagesNums").html(result.data.pageCount);
        } 
    });
}
//点击查询
$("#timerfilterBtn").on("click",function(){
  $("#timerfilterBtn").attr("data-coding",1);
  var dtu_id = $("#eventDtuId").val();
  var accountName = $("#eventkehuName").val();
  var module = $("#logmodules").val();
  var methods = $("#logmoduleMethods").val();
  var isSuccess = $("#logmoduleResult").val();
  var createStartDate = $("#startDate").val();
  var createStartEnd = $("#endDate").val();
  var pageNow = 1;
  var pageSize = 20;
  $.vloading.show();
    $.ajax({ 
        type:"post", 
        url:urls.checkHandellog, 
        data: {token:token,dtu_id:dtu_id,accountName:accountName,module:module,methods:methods,isSuccess:isSuccess,createStartDate:createStartDate,createStartEnd:createStartEnd,pageNow:pageNow,pageSize:pageSize}, 
        dataType: 'json', 
        async : true,
        success:function(result){
          $.vloading.remove();
            var  checkHandellogHtml = '';
            if(result.data.records.length==0){
              $(".checkHandellogHtml").html('<p class="txtc" style="padding:19px 0;font-size:16px;border-right:1px solid #e9e9e9;border-bottom:1px solid #e9e9e9;">暂无数据</p>');
            }else{
              for(var i=0;i<result.data.records.length;i++){
                  if(result.data.records[i].isSuccess==1){//0失败 1成功
                      checkHandellogHtml +='<div class="tableTReach clearfix">\n\
                            <div class="tablecommoncel-1 tableTBdpoint fl"><i data-ids="'+result.data.records[i].id+'" class="xwl i-checkno"></i></div>\n\
                            <div class="tablecommoncel-2 tableTBdZH fl oellipsis">'+result.data.records[i].accountName+'</div>\n\
                            <div class="tablecommoncel-3 tableTBdDTU fl">'+result.data.records[i].dtu_id+'</div>\n\
                            <div class="tablecommoncel-4 tableTBdMK fl oellipsis">'+result.data.records[i].module+'</div>\n\
                            <div class="tablecommoncel-5 tableTBdFF fl oellipsis">'+result.data.records[i].method+'</div>\n\
                            <div class="tablecommoncel-6 tableTBdIP fl oellipsis">'+result.data.records[i].userIP+'</div>\n\
                            <div class="tablecommoncel-7 tableTBdMS fl">'+result.data.records[i].description+'</div>\n\
                            <div class="tablecommoncel-8 tableTBdJG fl">成功</div>\n\
                            <div class="tablecommoncel-9 tableTBdSJ fl">'+result.data.records[i].operTime+'</div>\n\
                          </div>';
                  }else{
                      checkHandellogHtml +='<div class="tableTReach clearfix">\n\
                            <div class="tablecommoncel-1 tableTBdpoint fl"><i data-ids="'+result.data.records[i].id+'" class="xwl i-checkno"></i></div>\n\
                            <div class="tablecommoncel-2 tableTBdZH fl oellipsis">'+result.data.records[i].accountName+'</div>\n\
                            <div class="tablecommoncel-3 tableTBdDTU fl">'+result.data.records[i].dtu_id+'</div>\n\
                            <div class="tablecommoncel-4 tableTBdMK fl oellipsis">'+result.data.records[i].module+'</div>\n\
                            <div class="tablecommoncel-5 tableTBdFF fl oellipsis">'+result.data.records[i].method+'</div>\n\
                            <div class="tablecommoncel-6 tableTBdIP fl oellipsis">'+result.data.records[i].userIP+'</div>\n\
                            <div class="tablecommoncel-7 tableTBdMS fl">'+result.data.records[i].description+'</div>\n\
                            <div class="tablecommoncel-8 tableTBdJG fl">失败</div>\n\
                            <div class="tablecommoncel-9 tableTBdSJ fl">'+result.data.records[i].operTime+'</div>\n\
                          </div>';
                  }

              }
              $(".checkHandellogHtml").html(checkHandellogHtml);
            }

            //总条数
            $(".allRecord").html(result.data.rowCount);
            //总页数
            $(".allpagesNums").html(result.data.pageCount);
            $(".allpagesNums").html(result.data.pageCount);
            pageNav.go(1,result.data.pageCount);
            pageNav.fn = function(p,pn){
                getHandelLog(p);             
            };

        } 
    });
})

//删除操作日志START（包含批量）
//全选与单选START
$("body").on("click",".tableTBdpoint",function(){
  $(this).find("i").toggleClass("i-checked");  
})
$(".tableTHpoint").on("click",function(){
  $(".checkHandellogHtml .tableTReach i,.tableTHpoint i").toggleClass("i-checked");
  if($(".tableTHpoint i").hasClass("i-checked")){
    $(".checkHandellogHtml .tableTReach i").addClass("i-checked");
  }else{
    $(".checkHandellogHtml .tableTReach i").removeClass("i-checked");
  }
})
//全选与单选END
//删除按钮触发
$("#eventsDel").on("click",function(){
  //遍历选中的checkbox
  var choosedboxNums = document.querySelectorAll(".checkHandellogHtml .tableTReach .i-checked");
  var idsArry = [];
  for(var i = 0, j = choosedboxNums.length; i < j; i++){
    idsArry.push(choosedboxNums[i].attributes[0].value);
  }
  console.log(idsArry);
  if(choosedboxNums.length==0){
    $.flytip("请选择要删除的日志");
  }else{
    $.flytip("删除日志功能暂未支持");
    /*$.ajax({ 
        type:"post", 
        url:urls.checkHandellog, 
        data: {token:token,ids:idsArry.join(",")}, 
        dataType: 'json', 
        async : true,
        success:function(result){
          $.flytip(result.msg);
          if($(".tableTBdpoint i").hasClass("i-checked")){
            $(".tableTBdpoint i.i-checked").parent().parent().remove();
            if($(".tableTReach").length==0){
              location.reload();
            }
          }
        } 
    });*/    
  }
  
})

//删除操作日志END（包含批量）


//分页器optional set
//事件监听分页触发时，获得当前页码数
pageNav.pre="上一页";
pageNav.next="下一页";

//个人中心下拉
$("#showmyAccountMenu").toggle(
    function(){$("#toggleshowmenu").show();},
    function(){$("#toggleshowmenu").hide();}
);

//$.flytip("zhowdom");$.vloading.show();$.vloading.remove();
getOnelayerMenu();
getTwolayerMenu(601,605);
$(".mianshowbpt-r a").eq(3).addClass("cur");
getThreelayerMenu(605);


//获取模块
$.ajax({ 
      type:"post", 
      url:urls.getlogmodules, 
      data: {token:token}, 
      dataType: 'json', 
      async : true,
      success:function(result){
        var getlogModuleHtml = '';
        for(var i=0;i<result.data.length;i++){
          getlogModuleHtml +='<option value="'+result.data[i].id+'">'+result.data[i].module+'</option>';
        }
        $("#logmodules").html('<option value="" selected="selected">模块</option>'+getlogModuleHtml);

        $("#logmodules").change(function(){
          var selectedVal = $(this).val();
              $.ajax({ 
                type:"post", 
                url:urls.getlogMethods, 
                data: {token:token,module_id:selectedVal}, 
                dataType: 'json', 
                async : true, 
                success:function(result){
                  var getlogMethodsHtml = '';
                  for(var i=0;i<result.data.length;i++){
                    getlogMethodsHtml +='<option value="'+result.data[i].id+'">'+result.data[i].method+'</option>';
                  }
                  $("#logmoduleMethods").html('<option value="" selected="selected">方法</option>'+getlogMethodsHtml);
                } 
            });
        })

      } 
  });







//req.js end
})